package kr.hkit.androidcomplete02.ch03;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

public class TimePickerTest extends Activity {
	TimePicker mTime;
	TextView mTxtTime;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.time_picker_test);

		mTime = (TimePicker) findViewById(R.id.timepicker);
		mTxtTime = (TextView) findViewById(R.id.texttime);
		mTime.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {

			@Override
			public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
				mTxtTime.setText(String.format("%d:%d", hourOfDay, minute));
			}
		});

		findViewById(R.id.btntoggle24).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						mTime.setIs24HourView(!mTime.is24HourView());

					}
				});

		findViewById(R.id.btnnow).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						String result = String.format("%d시%d분",
								mTime.getCurrentHour(),
								mTime.getCurrentMinute());
						Toast.makeText(TimePickerTest.this, result, 0).show();
					}
				});
	}
}
